﻿namespace ACCOUNTING.LVY.Business
{
    using ACCOUNTING;
    using Microsoft.VisualBasic;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Data;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;

    public class clsChungTuQuy
    {
        private string mChungTuDinhKem = "";
        private string mDiaChi = "";
        private string mDienGiai = "";
        private string mDienThoai = "";
        private string mDuLieu = "NB";
        private int mDuyet = 0;
        private string mKhoa = "";
        private string mKhoaBoPhan = "";
        private string mKhoaDoiTuong = "";
        private string mKhoaDonVi = "";
        private string mKhoaHopDong = "";
        private string mKhoaNhanVienCapNhat = "";
        private string mKhoaSanPham = "";
        private string mKhoaTKChu = "";
        private string mLoaiChungTu = "";
        private string mLoaiTien = "";
        private string mNamThang = "";
        private string mNgayCapNhat = "";
        private string mNgayChungTu = "";
        private string mNguoiDaiDien = "";
        private int mSend = 0;
        private string mSoChungTu = "";
        private string mSoCMND = "";
        private double mSoTien = 0.0;
        private double mSoTienNT = 0.0;
        private double mTyGia = 0.0;

        public void ClearTemp(string pKeyTable)
        {
            string commandText = "DELETE FROM GL_ChungTuQuyChiTietTmp WHERE KhoaChungTu = '" + pKeyTable.Trim() + "'";
            DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]);
        }

        public bool DeleteData(string strKhoa, int CheckAmQuy = 1)
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[4];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@Khoa", DbType.Int64, ParameterDirection.Input, strKhoa);
                commandParameters[1] = DBHelper.createParameter("@CheckAmQuy", DbType.Double, ParameterDirection.Input, CheckAmQuy);
                commandParameters[2] = DBHelper.createParameter("@AmQuy", DbType.Double, ParameterDirection.Output, 0);
                commandParameters[3] = DBHelper.createParameter("@pError", DbType.Double, ParameterDirection.Output, 0);
                int num = DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "GL_sp_ChungTuQuyDel", commandParameters);
                if (Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectNotEqual(commandParameters[2].Value, 0, false))
                {
                    if (Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectNotEqual(commandParameters[3].Value, 0, false))
                    {
                        LVYModule.ShowWarning(modGeneral.Tranlated("Nghiệp vụ kh\x00f4ng thể thực hiện được v\x00ec \x00e2m quỹ!", ""));
                    }
                    return false;
                }
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public DataTable GetBanHangThanhToan(string NgayChungTu, string KhoaDonVi, string strKhoaThanhToan = "", string strKhoaNhanVien = "", string strKhoaKhachHang = "")
        {
            DataTable table;
            try
            {
                string str2 = " WHERE XB.LoaiChungTu = 'XB' AND XB.NgayChungTu <= '" + NgayChungTu + "' AND ((IsNull(XB.TienHang,0) - IsNull(XB.TienChietKhau,0) + IsNull(XB.TienThueVAT,0)) - IsNull(XB.DaThanhToan,0)) > 0 AND XB.GhiSo = 1  AND XB.KhoaDonVi = '" + KhoaDonVi + "'";
                if (strKhoaThanhToan.Trim() != "")
                {
                    str2 = str2 + " AND XB.Khoa NOT IN (SELECT KhoaChungTuThamChieu FROM GL_ChungTuQuyChiTiet Where KhoaChungTu = '" + strKhoaThanhToan.Trim() + "')";
                }
                if (strKhoaNhanVien.Trim() != "")
                {
                    str2 = str2 + " AND XB.KhoaNhanVienBanHang = '" + strKhoaNhanVien + "'";
                }
                if (strKhoaKhachHang.Trim() != "")
                {
                    str2 = str2 + " AND XB.KhoaDoiTuong = '" + strKhoaKhachHang + "'";
                }
                string commandText = " SELECT XB.Khoa, XB.SoChungTu, XB.NgayChungTu as Ngay, dbo.Char2Date(XB.NgayChungTu) As NgayChungTu, XB.SoHoaDon,dbo.Char2Date(XB.NgayThanhToan) as NgayThanhToan,  XB.LoaiTien,XB.TyGia, XB.TienHangNT - XB.TienChietKhauNT + XB.TienThueVATNT as TienHangNT,  XB.TienHang - XB.TienChietKhau + XB.TienThueVAT as TienHang, XB.DaThanhToanNT as DaThanhToan,  XB.KhoaTKThanhToan, TK.SoTaiKhoan, XB.KhoaDoiTuong, DT.Ten" + modGeneral.H_LANGUAGE + " as TenDoiTuong  FROM ST_XuatKho XB LEFT JOIN DM_TaiKhoan TK on XB.KhoaTKThanhToan = TK.Khoa  LEFT JOIN DM_DoiTuong DT on XB.KhoaDoiTuong = DT.Khoa " + str2 + " ORDER BY 3, 5";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDataPrint(string strKhoa)
        {
            DataTable table;
            try
            {
                string commandText = "  SELECT CTQ.Khoa, CTQ.NamThang, CTQ.SoChungTu, CTQ.NgayChungTu, CTQ.Diachi,  CTQ.DienThoai,  CTQ.NguoiDaiDien,CTQ.SoCMND, CTQ.LoaiTien, CTQ.LoaiChungTu, CTQ.ChungTuDinhKem , CTQ.TyGia, CTQ.SoTienNT, CTQ.SoTien, CTQCT.DienGiai,DT.TenVIET as DoiTuong,TK.SoTaiKhoan as SoTK  FROM GL_ChungTuQuyChiTiet CTQCT   Left join GL_ChungTuQuy CTQ on CTQCT.KhoaChungTu = CTQ.Khoa   Left join DM_DoiTuong DT on CTQCT.KhoaDoiTuong = DT.Khoa    Left join DM_TaiKhoan TK on CTQCT.KhoaTaiKhoan = TK.Khoa    Where CTQCT.KhoaChungTu = '" + strKhoa + "'";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDataPrintBaoCo(string strKhoa)
        {
            DataTable table;
            try
            {
                string commandText = "  SELECT CTQ.Khoa, CTQ.NamThang, CTQ.SoChungTu, CTQ.NgayChungTu, CTQ.Diachi,  CTQ.DienThoai,  CTQ.NguoiDaiDien,CTQ.SoCMND, CTQ.LoaiTien, CTQ.LoaiChungTu, CTQ.ChungTuDinhKem , CTQ.TyGia, CTQ.SoTienNT, CTQ.SoTien, CTQ.DienGiai,DT.Ten" + modGeneral.H_LANGUAGE + " as DoiTuong,TK.SoTaiKhoan as SoTK,DTT.Ten" + modGeneral.H_LANGUAGE + " as NganHang   FROM GL_ChungTuQuyChiTiet CTQCT   Left join GL_ChungTuQuy CTQ on CTQCT.KhoaChungTu = CTQ.Khoa   Left join DM_DoiTuong DT on CTQCT.KhoaDoiTuong = DT.Khoa    Left join DM_DoiTuong DTT on CTQCT.KhoaDoiTuong = DTT.Khoa    Left join DM_TaiKhoan TK on CTQCT.KhoaTaiKhoan = TK.Khoa    Where CTQCT.KhoaChungTu = '" + strKhoa + "' And CTQ.LoaiChungTu = 'BC' ";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDataPrintBaoNo(string strKhoa)
        {
            DataTable table;
            try
            {
                string commandText = "  SELECT CTQ.Khoa, CTQ.NamThang, CTQ.SoChungTu, CTQ.NgayChungTu, CTQ.Diachi,  CTQ.DienThoai,  CTQ.NguoiDaiDien,CTQ.SoCMND, CTQ.LoaiTien, CTQ.LoaiChungTu, CTQ.ChungTuDinhKem , CTQ.TyGia, CTQ.SoTienNT, CTQ.SoTien, CTQ.DienGiai,DT.Ten" + modGeneral.H_LANGUAGE + " as DoiTuong,TK.SoTaiKhoan as SoTK,DTT.Ten" + modGeneral.H_LANGUAGE + " as NganHang   FROM GL_ChungTuQuyChiTiet CTQCT   Left join GL_ChungTuQuy CTQ on CTQCT.KhoaChungTu = CTQ.Khoa   Left join DM_DoiTuong DT on CTQCT.KhoaDoiTuong = DT.Khoa    Left join DM_DoiTuong DTT on CTQCT.KhoaDoiTuong = DTT.Khoa    Left join DM_TaiKhoan TK on CTQCT.KhoaTaiKhoan = TK.Khoa    Where CTQCT.KhoaChungTu = '" + strKhoa + "' And CTQ.LoaiChungTu = 'BN' ";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDataPrintCT(string strKhoa)
        {
            DataTable table;
            IDataParameter[] commandParameters = new IDataParameter[2];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@Khoa", DbType.Int64, ParameterDirection.Input, strKhoa);
                commandParameters[1] = DBHelper.createParameter("@pError", DbType.Double, ParameterDirection.Input, 0);
                return DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.StoredProcedure, "GL_BC_PhieuThuChiTiet", commandParameters).Tables[0];
                if (Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectNotEqual(commandParameters[1].Value, 0, false))
                {
                    return null;
                }
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetList(string strCondition = "")
        {
            DataTable table;
            string str2 = "";
            try
            {
                if (strCondition.Trim() != "")
                {
                    str2 = " WHERE " + strCondition;
                }
                string commandText = "SELECT DISTINCT GL.Khoa, GL.SoChungTu, dbo.Char2Date(GL.NgayChungTu) as NgayChungTu, GL.ChungTuDinhKem,  GL.SoTienNT, GL.SoTien, GL.DienGiai FROM GL_ChungTuQuy GL LEFT JOIN GL_ChungTuQuyChiTiet CT ON GL.Khoa = CT.KhoaChungTu " + str2;
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetListDetailsBanRa(string strKhoa)
        {
            DataTable table;
            try
            {
                string commandText = " SELECT CT.Khoa, CT.KhoaTaiKhoan, TK.SoTaiKhoan, CT.KhoaDoiTuong, DT.Ten" + modGeneral.H_LANGUAGE + " as DoiTuong, CT.KhoaChungTuThamChieu, CT.SoChungTuThamChieu,  CT.SoTienNT, CT.SoTien, CT.KhoaTaiKhoanThue, TKT.SoTaiKhoan as TaiKhoanThue, CT.KhoaBoPhan, BP.TenViet as BoPhan,  CT.KhoaSanPham, SP.Ten" + modGeneral.H_LANGUAGE + " as SanPham, CT.KhoaHopDong, HD.SoHopDong, CT.Khoa, CT.KhoaLoaiThue, LT.Ma as LoaiThue,  CT.TyLeThue, CT.TienThueNT, CT.TienThue, CT.SoHoaDon, dbo.Char2Date(CT.NgayHoaDon) as NgayHoaDon,  CT.SoSeri, CT.KhoaDoiTuongThue, CT.TenDoiTuongThue, CT.MaSoThue, CT.DiaChiThue, CT.DienGiai,  CT.KhoaLoaiChungTu, CP.Ten" + modGeneral.H_LANGUAGE + " as ChiPhi, CT.FlagTamUng  FROM GL_ChungTuQuyChiTiet CT LEFT JOIN DM_TaiKhoan TK on CT.KhoaTaiKhoan = TK.Khoa  LEFT JOIN DM_TaiKhoan TKT on CT.KhoaTaiKhoanThue = TKT.Khoa  LEFT JOIN DM_DoiTuong DT on CT.KhoaDoiTuong = DT.Khoa  LEFT JOIN DM_DonViBoPhan BP on CT.KhoaBoPhan = BP.Khoa  LEFT JOIN DM_SanPhamCongViec SP on CT.KhoaSanPham = SP.Khoa  LEFT JOIN DM_HopDong HD on CT.KhoaHopDong = HD.Khoa  LEFT JOIN DM_LoaiHoaDon LT on CT.KhoaLoaiThue = LT.Khoa  LEFT JOIN DM_KhoanMucChiPhi CP on CT.KhoaLoaiChungTu = CP.Khoa  WHERE CT.KhoaChungTu = '" + strKhoa + "'";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetListDetailsDauVao(string strKhoa)
        {
            DataTable table;
            try
            {
                string commandText = " SELECT CT.Khoa, CT.KhoaTaiKhoan, TK.SoTaiKhoan, CT.KhoaDoiTuong, DT.Ten" + modGeneral.H_LANGUAGE + " as DoiTuong, CT.KhoaChungTuThamChieu, CT.SoChungTuThamChieu,  CT.SoTienNT, CT.SoTien, CT.KhoaTaiKhoanThue, TKT.SoTaiKhoan as TaiKhoanThue, CT.KhoaBoPhan, BP.TenViet as BoPhan,  CT.KhoaSanPham, SP.Ten" + modGeneral.H_LANGUAGE + " as SanPham, CT.KhoaHopDong, HD.SoHopDong, CT.Khoa, CT.KhoaLoaiThue, LT.Ma as LoaiThue,  CT.TyLeThue, CT.TienThueNT, CT.TienThue, CT.SoHoaDon, dbo.Char2Date(CT.NgayHoaDon) as NgayHoaDon,  CT.SoSeri, CT.KhoaDoiTuongThue, CT.TenDoiTuongThue, CT.MaSoThue, CT.DiaChiThue, CT.DienGiai,  CT.KhoaLoaiChungTu, CP.Ten" + modGeneral.H_LANGUAGE + " as ChiPhi, CT.FlagTamUng  FROM GL_ChungTuQuyChiTiet CT LEFT JOIN DM_TaiKhoan TK on CT.KhoaTaiKhoan = TK.Khoa  LEFT JOIN DM_TaiKhoan TKT on CT.KhoaTaiKhoanThue = TKT.Khoa  LEFT JOIN DM_DoiTuong DT on CT.KhoaDoiTuong = DT.Khoa  LEFT JOIN DM_DonViBoPhan BP on CT.KhoaBoPhan = BP.Khoa  LEFT JOIN DM_SanPhamCongViec SP on CT.KhoaSanPham = SP.Khoa  LEFT JOIN DM_HopDong HD on CT.KhoaHopDong = HD.Khoa  LEFT JOIN DM_HangMucBaoCaoThue LT on CT.KhoaLoaiThue = LT.Khoa  LEFT JOIN DM_KhoanMucChiPhi CP on CT.KhoaLoaiChungTu = CP.Khoa  WHERE CT.KhoaChungTu = '" + strKhoa + "'";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetListTimKiem(string pKhoaDonVi, string pTuNgay, string pDenNgay, string pLoaiChungTu, string pKhoaTaiKhoanDoi, string pKhoaDoiTuong, string pKhoaKhoanMuc)
        {
            DataTable table;
            IDataParameter[] commandParameters = new IDataParameter[7];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, pKhoaDonVi);
                commandParameters[1] = DBHelper.createParameter("@TuNgay", DbType.Int64, ParameterDirection.Input, pTuNgay);
                commandParameters[2] = DBHelper.createParameter("@DenNgay", DbType.Int64, ParameterDirection.Input, pDenNgay);
                commandParameters[3] = DBHelper.createParameter("@LoaiChungTu", DbType.Int64, ParameterDirection.Input, pLoaiChungTu);
                commandParameters[4] = DBHelper.createParameter("@KhoaTaiKhoanDoi", DbType.Int64, ParameterDirection.Input, pKhoaTaiKhoanDoi);
                commandParameters[5] = DBHelper.createParameter("@KhoaDoiTuong", DbType.Int64, ParameterDirection.Input, pKhoaDoiTuong);
                commandParameters[6] = DBHelper.createParameter("@KhoaKhoanMuc", DbType.Int64, ParameterDirection.Input, pKhoaKhoanMuc);
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.StoredProcedure, "GL_GetListChungTuQuy", commandParameters).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public void GetSoTaiKhoan(string strKhoa, ref string strTKNo, ref string strTKCo)
        {
            string commandText = "";
            clsDMTaiKhoan khoan = new clsDMTaiKhoan();
            int num = 0;
            string str4 = "";
            string str5 = "";
            strTKNo = "";
            strTKCo = "";
            try
            {
                this.Load(strKhoa);
                khoan.Load(this.mKhoaTKChu);
                str4 = LVYModule.ReturnIfNull(khoan.SoTaiKhoan, "", modGeneral.TypeOfValue.Nothing).ToString().Trim();
                commandText = "SELECT Distinct(SoTaiKhoan) as SoTaiKhoan FROM DM_TaiKhoan Where Khoa in (Select KhoaTaiKhoan  FROM GL_ChungTuQuyChiTiet Where KhoaChungTu = '" + strKhoa + "')";
                DataTable table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
                if (table != null)
                {
                    int num2 = table.Rows.Count - 1;
                    for (num = 0; num <= num2; num++)
                    {
                        if (str5.Trim() == "")
                        {
                            str5 = table.Rows[num]["SoTaiKhoan"].ToString().Trim();
                        }
                        else
                        {
                            str5 = strTKNo + "," + table.Rows[num]["SoTaiKhoan"].ToString().Trim();
                        }
                    }
                    commandText = "SELECT Distinct(SoTaiKhoan) as SoTaiKhoan FROM DM_TaiKhoan Where Khoa in (Select KhoaTaiKhoanThue  FROM GL_ChungTuQuyChiTiet Where KhoaChungTu = '" + strKhoa + "')";
                    table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
                    if (table != null)
                    {
                        int num3 = table.Rows.Count - 1;
                        for (num = 0; num <= num3; num++)
                        {
                            if (str5.Trim() == "")
                            {
                                str5 = table.Rows[num]["SoTaiKhoan"].ToString().Trim();
                            }
                            else
                            {
                                str5 = str5 + "," + table.Rows[num]["SoTaiKhoan"].ToString().Trim();
                            }
                        }
                        if ((this.mLoaiChungTu == "PT") | (this.mLoaiChungTu == "BC"))
                        {
                            strTKNo = str4;
                            strTKCo = str5;
                        }
                        else
                        {
                            strTKNo = str5;
                            strTKCo = str4;
                        }
                    }
                }
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                strTKNo = "";
                strTKCo = "";
                ProjectData.ClearProjectError();
            }
        }

        public bool IsDuplicateVoucherNo(string strVoucherNo, string strKeyTable)
        {
            string commandText = "SELECT * FROM GL_ChungTuQuy Where Rtrim(SoChungTu) = '" + strVoucherNo.Trim() + "' AND Khoa <> '" + strKeyTable + "'";
            return (DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0].Rows.Count > 0);
        }

        public bool Load(string pKhoa)
        {
            bool flag=false;
            try
            {
                string commandText = "SELECT * FROM GL_ChungTuQuy WHERE Khoa = '" + pKhoa + "'";
                IDataReader dataReader = DBHelper.ExecuteReader(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]);
                if (dataReader.Read())
                {
                    this.mKhoa = Conversions.ToString(modGeneral.GetValue(dataReader, 0, modGeneral.typeOfColumn.GetString));
                    this.mNamThang = Conversions.ToString(modGeneral.GetValue(dataReader, 1, modGeneral.typeOfColumn.GetString));
                    this.mSoChungTu = Conversions.ToString(modGeneral.GetValue(dataReader, 2, modGeneral.typeOfColumn.GetString));
                    this.mNgayChungTu = Conversions.ToString(modGeneral.GetValue(dataReader, 3, modGeneral.typeOfColumn.GetString));
                    this.mKhoaDoiTuong = Conversions.ToString(modGeneral.GetValue(dataReader, 4, modGeneral.typeOfColumn.GetString));
                    this.mKhoaBoPhan = Conversions.ToString(modGeneral.GetValue(dataReader, 5, modGeneral.typeOfColumn.GetString));
                    this.mKhoaSanPham = Conversions.ToString(modGeneral.GetValue(dataReader, 6, modGeneral.typeOfColumn.GetString));
                    this.mKhoaHopDong = Conversions.ToString(modGeneral.GetValue(dataReader, 7, modGeneral.typeOfColumn.GetString));
                    this.mDiaChi = Conversions.ToString(modGeneral.GetValue(dataReader, 8, modGeneral.typeOfColumn.GetString));
                    this.mDienThoai = Conversions.ToString(modGeneral.GetValue(dataReader, 9, modGeneral.typeOfColumn.GetString));
                    this.mNguoiDaiDien = Conversions.ToString(modGeneral.GetValue(dataReader, 10, modGeneral.typeOfColumn.GetString));
                    this.mSoCMND = Conversions.ToString(modGeneral.GetValue(dataReader, 11, modGeneral.typeOfColumn.GetString));
                    this.mDienGiai = Conversions.ToString(modGeneral.GetValue(dataReader, 12, modGeneral.typeOfColumn.GetString));
                    this.mLoaiTien = Conversions.ToString(modGeneral.GetValue(dataReader, 13, modGeneral.typeOfColumn.GetString));
                    this.mTyGia = Conversions.ToDouble(modGeneral.GetValue(dataReader, 14, modGeneral.typeOfColumn.GetDecimal));
                    this.mSoTienNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 15, modGeneral.typeOfColumn.GetDecimal));
                    this.mSoTien = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x10, modGeneral.typeOfColumn.GetDecimal));
                    this.mLoaiChungTu = Conversions.ToString(modGeneral.GetValue(dataReader, 0x11, modGeneral.typeOfColumn.GetString));
                    this.mKhoaTKChu = Conversions.ToString(modGeneral.GetValue(dataReader, 0x12, modGeneral.typeOfColumn.GetString));
                    this.mChungTuDinhKem = Conversions.ToString(modGeneral.GetValue(dataReader, 0x13, modGeneral.typeOfColumn.GetString));
                    this.mKhoaDonVi = Conversions.ToString(modGeneral.GetValue(dataReader, 20, modGeneral.typeOfColumn.GetString));
                    this.mKhoaNhanVienCapNhat = Conversions.ToString(modGeneral.GetValue(dataReader, 0x15, modGeneral.typeOfColumn.GetString));
                    this.mNgayCapNhat = Conversions.ToString(modGeneral.GetValue(dataReader, 0x16, modGeneral.typeOfColumn.GetString));
                    this.mSend = Conversions.ToInteger(modGeneral.GetValue(dataReader, 0x17, modGeneral.typeOfColumn.GetInt32));
                    this.mDuLieu = Conversions.ToString(modGeneral.GetValue(dataReader, 0x18, modGeneral.typeOfColumn.GetString));
                    this.mDuyet = Conversions.ToInteger(modGeneral.GetValue(dataReader, 0x19, modGeneral.typeOfColumn.GetInt32));
                }
                dataReader.Close();
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public DataTable RptBangKePhieuChi(string strKhoaDonVi, string strTuNgay, string strDenNgay, string strKhoaTaiKhoan)
        {
            DataTable table;
            IDataParameter[] commandParameters = new IDataParameter[6];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, strKhoaDonVi);
                commandParameters[1] = DBHelper.createParameter("@TuNgay", DbType.Int64, ParameterDirection.Input, strTuNgay);
                commandParameters[2] = DBHelper.createParameter("@DenNgay", DbType.Int64, ParameterDirection.Input, strDenNgay);
                commandParameters[3] = DBHelper.createParameter("@KhoaTaiKhoan", DbType.Int64, ParameterDirection.Input, strKhoaTaiKhoan);
                commandParameters[4] = DBHelper.createParameter("@KhoaDoiTuong", DbType.Int64, ParameterDirection.Input, "");
                commandParameters[5] = DBHelper.createParameter("@Language", DbType.Int64, ParameterDirection.Input, modGeneral.H_LANGUAGE);
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.StoredProcedure, "BC_sp_BangKePhieuChi", commandParameters).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable RptBangKePhieuThu(string strKhoaDonVi, string strTuNgay, string strDenNgay, string strKhoaTaiKhoan)
        {
            DataTable table;
            IDataParameter[] commandParameters = new IDataParameter[6];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, strKhoaDonVi);
                commandParameters[1] = DBHelper.createParameter("@TuNgay", DbType.Int64, ParameterDirection.Input, strTuNgay);
                commandParameters[2] = DBHelper.createParameter("@DenNgay", DbType.Int64, ParameterDirection.Input, strDenNgay);
                commandParameters[3] = DBHelper.createParameter("@KhoaTaiKhoan", DbType.Int64, ParameterDirection.Input, strKhoaTaiKhoan);
                commandParameters[4] = DBHelper.createParameter("@KhoaDoiTuong", DbType.Int64, ParameterDirection.Input, "");
                commandParameters[5] = DBHelper.createParameter("@Language", DbType.Int64, ParameterDirection.Input, modGeneral.H_LANGUAGE);
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.StoredProcedure, "BC_sp_BangKePhieuThu", commandParameters).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable RptQuyTienGoiNganHang(string strKhoaDonVi, string strTuNgay, string strDenNgay, string strKhoaTaiKhoan, string strKhoaDoiTuong, string StrLoaiTien = "")
        {
            DataTable table;
            IDataParameter[] commandParameters = new IDataParameter[7];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, strKhoaDonVi);
                commandParameters[1] = DBHelper.createParameter("@TuNgay", DbType.Int64, ParameterDirection.Input, strTuNgay);
                commandParameters[2] = DBHelper.createParameter("@DenNgay", DbType.Int64, ParameterDirection.Input, strDenNgay);
                commandParameters[3] = DBHelper.createParameter("@KhoaTaiKhoan", DbType.Int64, ParameterDirection.Input, strKhoaTaiKhoan);
                commandParameters[4] = DBHelper.createParameter("@KhoaDoiTuong", DbType.Int64, ParameterDirection.Input, strKhoaDoiTuong);
                commandParameters[5] = DBHelper.createParameter("@Language", DbType.Int64, ParameterDirection.Input, modGeneral.H_LANGUAGE);
                commandParameters[6] = DBHelper.createParameter("@LoaiTien", DbType.Int64, ParameterDirection.Input, StrLoaiTien.Trim());
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.StoredProcedure, "GL_BC_SoQuyTienGoiNganHang", commandParameters).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable RptQuyTienMat(string strKhoaDonVi, string strTuNgay, string strDenNgay, string strKhoaTaiKhoan, string strLoaiTien = "")
        {
            DataTable table;
            IDataParameter[] commandParameters = new IDataParameter[7];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, strKhoaDonVi);
                commandParameters[1] = DBHelper.createParameter("@TuNgay", DbType.Int64, ParameterDirection.Input, strTuNgay);
                commandParameters[2] = DBHelper.createParameter("@DenNgay", DbType.Int64, ParameterDirection.Input, strDenNgay);
                commandParameters[3] = DBHelper.createParameter("@KhoaTaiKhoan", DbType.Int64, ParameterDirection.Input, strKhoaTaiKhoan);
                commandParameters[4] = DBHelper.createParameter("@KhoaDoiTuong", DbType.Int64, ParameterDirection.Input, "");
                commandParameters[5] = DBHelper.createParameter("@Language", DbType.Int64, ParameterDirection.Input, modGeneral.H_LANGUAGE);
                commandParameters[6] = DBHelper.createParameter("@LoaiTien", DbType.Int64, ParameterDirection.Input, strLoaiTien.Trim());
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.StoredProcedure, "GL_BC_SoQuyTienMat", commandParameters).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public bool Save()
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[0x1c];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@Khoa", DbType.Int64, ParameterDirection.Input, this.mKhoa);
                commandParameters[1] = DBHelper.createParameter("@NamThang", DbType.Int64, ParameterDirection.Input, this.mNamThang);
                commandParameters[2] = DBHelper.createParameter("@SoChungTu", DbType.Int64, ParameterDirection.Input, this.mSoChungTu);
                commandParameters[3] = DBHelper.createParameter("@NgayChungTu", DbType.Int64, ParameterDirection.Input, this.mNgayChungTu);
                commandParameters[4] = DBHelper.createParameter("@KhoaDoiTuong", DbType.Int64, ParameterDirection.Input, this.mKhoaDoiTuong);
                commandParameters[5] = DBHelper.createParameter("@KhoaBoPhan", DbType.Int64, ParameterDirection.Input, this.mKhoaBoPhan);
                commandParameters[6] = DBHelper.createParameter("@KhoaSanPham", DbType.Int64, ParameterDirection.Input, this.mKhoaSanPham);
                commandParameters[7] = DBHelper.createParameter("@KhoaHopDong", DbType.Int64, ParameterDirection.Input, this.mKhoaHopDong);
                commandParameters[8] = DBHelper.createParameter("@DiaChi", DbType.Int64, ParameterDirection.Input, this.mDiaChi);
                commandParameters[9] = DBHelper.createParameter("@DienThoai", DbType.Int64, ParameterDirection.Input, this.mDienThoai);
                commandParameters[10] = DBHelper.createParameter("@NguoiDaiDien", DbType.Int64, ParameterDirection.Input, this.mNguoiDaiDien);
                commandParameters[11] = DBHelper.createParameter("@SoCMND", DbType.Int64, ParameterDirection.Input, this.mSoCMND);
                commandParameters[12] = DBHelper.createParameter("@DienGiai", DbType.Int64, ParameterDirection.Input, this.mDienGiai);
                commandParameters[13] = DBHelper.createParameter("@LoaiTien", DbType.Int64, ParameterDirection.Input, this.mLoaiTien);
                commandParameters[14] = DBHelper.createParameter("@TyGia", DbType.Date, ParameterDirection.Input, this.mTyGia);
                commandParameters[15] = DBHelper.createParameter("@SoTienNT", DbType.Date, ParameterDirection.Input, this.mSoTienNT);
                commandParameters[0x10] = DBHelper.createParameter("@SoTien", DbType.Date, ParameterDirection.Input, this.mSoTien);
                commandParameters[0x11] = DBHelper.createParameter("@LoaiChungTu", DbType.Int64, ParameterDirection.Input, this.mLoaiChungTu);
                commandParameters[0x12] = DBHelper.createParameter("@KhoaTKChu", DbType.Int64, ParameterDirection.Input, this.mKhoaTKChu);
                commandParameters[0x13] = DBHelper.createParameter("@ChungTuDinhKem", DbType.Int64, ParameterDirection.Input, this.mChungTuDinhKem);
                commandParameters[20] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, this.mKhoaDonVi);
                commandParameters[0x15] = DBHelper.createParameter("@KhoaNhanVienCapNhat", DbType.Int64, ParameterDirection.Input, this.mKhoaNhanVienCapNhat);
                commandParameters[0x16] = DBHelper.createParameter("@NgayCapNhat", DbType.Int64, ParameterDirection.Input, this.mNgayCapNhat);
                commandParameters[0x17] = DBHelper.createParameter("@Send", DbType.Double, ParameterDirection.Input, this.mSend);
                commandParameters[0x18] = DBHelper.createParameter("@DuLieu", DbType.Int64, ParameterDirection.Input, this.mDuLieu);
                commandParameters[0x19] = DBHelper.createParameter("@Duyet", DbType.Double, ParameterDirection.Input, this.mDuyet);
                commandParameters[0x1a] = DBHelper.createParameter("@AmQuy", DbType.Double, ParameterDirection.Output, 0);
                commandParameters[0x1b] = DBHelper.createParameter("@pError", DbType.Double, ParameterDirection.Output, 0);
                int num = DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "GL_sp_ChungTuQuy", commandParameters);
                if (Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectEqual(commandParameters[0x1b].Value, 0, false))
                {
                    return true;
                }
                if (Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectNotEqual(commandParameters[0x1a].Value, 0, false))
                {
                    LVYModule.ShowWarning(modGeneral.Tranlated("Nghiệp vụ kh\x00f4ng thể thực hiện được v\x00ec \x00e2m quỹ!", ""));
                }
                flag = false;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public DataTable ShowListByField(string strFieldList, string strConditions = "", string strOrder = "")
        {
            DataTable table;
            string commandText = "";
            IDataParameter parameter = null;
            string str3 = "";
            string str = "";
            strFieldList = Strings.Replace(strFieldList, "|", ",", 1, -1, CompareMethod.Binary);
            try
            {
                if (strConditions.Trim() != "")
                {
                    str3 = " WHERE " + strConditions;
                }
                if (strOrder.Trim() != "")
                {
                    str = " ORDER BY " + strOrder;
                }
                commandText = "SELECT Khoa, NamThang, SoChungTu, NgayChungTu, Diachi,  DienThoai, NguoiDaiDien, SoCMND, LoaiTien, LoaiChungTu, ChungTuDinhKem  TyGia, SoTienNT, SoTien, DienGiai FROM GL_ChungTuQuy " + str3 + " ORDER BY 2, 5, 4";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[] { parameter }).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public string ChungTuDinhKem
        {
            get
            {
                return this.mChungTuDinhKem;
            }
            set
            {
                this.mChungTuDinhKem = value;
            }
        }

        public string DiaChi
        {
            get
            {
                return this.mDiaChi;
            }
            set
            {
                this.mDiaChi = value;
            }
        }

        public string DienGiai
        {
            get
            {
                return this.mDienGiai;
            }
            set
            {
                this.mDienGiai = value;
            }
        }

        public string DienThoai
        {
            get
            {
                return this.mDienThoai;
            }
            set
            {
                this.mDienThoai = value;
            }
        }

        public string DuLieu
        {
            get
            {
                return this.mDuLieu;
            }
            set
            {
                this.mDuLieu = value;
            }
        }

        public int Duyet
        {
            get
            {
                return this.mDuyet;
            }
            set
            {
                this.mDuLieu = Conversions.ToString(value);
            }
        }

        public string Khoa
        {
            get
            {
                return this.mKhoa;
            }
            set
            {
                this.mKhoa = value;
            }
        }

        public string KhoaBoPhan
        {
            get
            {
                return this.mKhoaBoPhan;
            }
            set
            {
                this.mKhoaBoPhan = value;
            }
        }

        public string KhoaDoiTuong
        {
            get
            {
                return this.mKhoaDoiTuong;
            }
            set
            {
                this.mKhoaDoiTuong = value;
            }
        }

        public string KhoaDonVi
        {
            get
            {
                return this.mKhoaDonVi;
            }
            set
            {
                this.mKhoaDonVi = value;
            }
        }

        public string KhoaHopDong
        {
            get
            {
                return this.mKhoaHopDong;
            }
            set
            {
                this.mKhoaHopDong = value;
            }
        }

        public string KhoaNhanVienCapNhat
        {
            get
            {
                return this.mKhoaNhanVienCapNhat;
            }
            set
            {
                this.mKhoaNhanVienCapNhat = value;
            }
        }

        public string KhoaSanPham
        {
            get
            {
                return this.mKhoaSanPham;
            }
            set
            {
                this.mKhoaSanPham = value;
            }
        }

        public string KhoaTKChu
        {
            get
            {
                return this.mKhoaTKChu;
            }
            set
            {
                this.mKhoaTKChu = value;
            }
        }

        public string LoaiChungTu
        {
            get
            {
                return this.mLoaiChungTu;
            }
            set
            {
                this.mLoaiChungTu = value;
            }
        }

        public string LoaiTien
        {
            get
            {
                return this.mLoaiTien;
            }
            set
            {
                this.mLoaiTien = value;
            }
        }

        public string NamThang
        {
            get
            {
                return this.mNamThang;
            }
            set
            {
                this.mNamThang = value;
            }
        }

        public string NgayCapNhat
        {
            get
            {
                return this.mNgayCapNhat;
            }
            set
            {
                this.mNgayCapNhat = value;
            }
        }

        public string NgayChungTu
        {
            get
            {
                return this.mNgayChungTu;
            }
            set
            {
                this.mNgayChungTu = value;
            }
        }

        public string NguoiDaiDien
        {
            get
            {
                return this.mNguoiDaiDien;
            }
            set
            {
                this.mNguoiDaiDien = value;
            }
        }

        public int Send
        {
            get
            {
                return this.mSend;
            }
            set
            {
                this.mSend = value;
            }
        }

        public string SoChungTu
        {
            get
            {
                return this.mSoChungTu;
            }
            set
            {
                this.mSoChungTu = value;
            }
        }

        public string SoCMND
        {
            get
            {
                return this.mSoCMND;
            }
            set
            {
                this.mSoCMND = value;
            }
        }

        public double SoTien
        {
            get
            {
                return this.mSoTien;
            }
            set
            {
                this.mSoTien = value;
            }
        }

        public double SoTienNT
        {
            get
            {
                return this.mSoTienNT;
            }
            set
            {
                this.mSoTienNT = value;
            }
        }

        public double TyGia
        {
            get
            {
                return this.mTyGia;
            }
            set
            {
                this.mTyGia = value;
            }
        }
    }
}

